//
//  MyFirrstViewController.m
//  MyProject
//
//  Created by dllo on 15/11/3.
//  Copyright © 2015年 蓝鸥科技. All rights reserved.
//

#import "MyFirrstViewController.h"
#import "MyArticleViewController.h"
#import "MybutifulgoodsViewController.h"
#import <UIImageView+WebCache.h>

@interface MyFirrstViewController ()
- (IBAction)ButifulGood:(UIButton *)sender;
- (IBAction)mode:(UIButton *)sender;
- (IBAction)memory:(id)sender;
- (IBAction)good:(UIButton *)sender;
@property (weak, nonatomic) IBOutlet UILabel *cangLabel;
@property (weak, nonatomic) IBOutlet UILabel *MwenLabel;
@property (weak, nonatomic) IBOutlet UILabel *MwuLabel;
@property (weak, nonatomic) IBOutlet UILabel *sheLabel;
@property (weak, nonatomic) IBOutlet UILabel *yejianLabel;

@property (weak, nonatomic) IBOutlet UILabel *qingLabel;
@property (weak, nonatomic) IBOutlet UILabel *tLabel;
@property (weak, nonatomic) IBOutlet UILabel *trLabel;
@property (weak, nonatomic) IBOutlet UILabel *forLabel;
@property (weak, nonatomic) IBOutlet UILabel *oneLabel;

@end

@implementation MyFirrstViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    
    
    
    //[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"t2.png"] forBarMetrics:UIBarMetricsDefault];
}

- (void)viewWillAppear:(BOOL)animated
{
    
    if (![[NSUserDefaults standardUserDefaults]boolForKey:@"isWhite"]) {
        self.cangLabel.textColor = [UIColor whiteColor];
        self.MwuLabel.textColor = [UIColor whiteColor];
        self.MwenLabel.textColor = [UIColor whiteColor];
        self.sheLabel.textColor = [UIColor whiteColor];
        self.yejianLabel.textColor = [UIColor whiteColor];
        self.qingLabel.textColor = [UIColor whiteColor];
        self.oneLabel.textColor = [UIColor whiteColor];
        self.tLabel.textColor = [UIColor whiteColor];
        self.trLabel.textColor = [UIColor whiteColor];
        self.forLabel.textColor = [UIColor whiteColor];
        
        self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
        self.navigationController.navigationBar.barTintColor = [UIColor blackColor];
        
        [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],NSForegroundColorAttributeName,nil]];
    }
    else{
        self.cangLabel.textColor = [UIColor blackColor];
        self.MwuLabel.textColor = [UIColor grayColor];
        self.MwenLabel.textColor = [UIColor grayColor];
        self.sheLabel.textColor = [UIColor blackColor];
        self.yejianLabel.textColor = [UIColor grayColor];
        self.qingLabel.textColor = [UIColor grayColor];
        self.oneLabel.textColor = [UIColor grayColor];
        self.tLabel.textColor = [UIColor grayColor];
        self.trLabel.textColor = [UIColor grayColor];
        self.forLabel.textColor = [UIColor grayColor];
        self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
        self.navigationController.navigationBar.barTintColor = [UIColor redColor];
        
        [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],NSForegroundColorAttributeName,nil]];
        
    }
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}




/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/


///Users/dllo/FiveMinite/MyProject副本 2/MyProject/My/Controller/MyArticleViewController.h美文收藏:
- (IBAction)ButifulGood:(UIButton *)sender
{
    MyArticleViewController *article = [[MyArticleViewController alloc]init];
    [self.navigationController pushViewController:article animated:YES];
}

//夜间:
- (IBAction)mode:(UIButton *)sender
{
      BOOL result = ![[NSUserDefaults standardUserDefaults]boolForKey:@"isWhite"];
    [[NSUserDefaults standardUserDefaults]setBool:result forKey:@"isWhite"];
    NSLog(@"%hhd",[[NSUserDefaults standardUserDefaults]boolForKey:@"isWhite"]);
    NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
    [center postNotificationName:@"change" object:nil userInfo:nil];
    
    if (![[NSUserDefaults standardUserDefaults]boolForKey:@"isWhite"]) {
        self.cangLabel.textColor = [UIColor whiteColor];
        self.MwuLabel.textColor = [UIColor whiteColor];
        self.MwenLabel.textColor = [UIColor whiteColor];
        self.sheLabel.textColor = [UIColor whiteColor];
        self.yejianLabel.textColor = [UIColor whiteColor];
        self.qingLabel.textColor = [UIColor whiteColor];
        self.oneLabel.textColor = [UIColor whiteColor];
        self.tLabel.textColor = [UIColor whiteColor];
        self.trLabel.textColor = [UIColor whiteColor];
        self.forLabel.textColor = [UIColor whiteColor];
        
        self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
        self.navigationController.navigationBar.barTintColor = [UIColor blackColor];
        
        [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],NSForegroundColorAttributeName,nil]];

        
    }
    else{
        self.cangLabel.textColor = [UIColor blackColor];
        self.MwuLabel.textColor = [UIColor grayColor];
        self.MwenLabel.textColor = [UIColor grayColor];
        self.sheLabel.textColor = [UIColor blackColor];
        self.yejianLabel.textColor = [UIColor grayColor];
        self.qingLabel.textColor = [UIColor grayColor];
        self.oneLabel.textColor = [UIColor grayColor];
        self.tLabel.textColor = [UIColor grayColor];
        self.trLabel.textColor = [UIColor grayColor];
        self.forLabel.textColor = [UIColor grayColor];
        
        
        self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
        self.navigationController.navigationBar.barTintColor = [UIColor redColor];
        
        [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],NSForegroundColorAttributeName,nil]];

        
    }
}



//轻缓:

- (IBAction)memory:(id)sender
{
 CGFloat size = [self sizeOfClear];
    CGFloat sizeSd = [[SDImageCache sharedImageCache] getSize];
    CGFloat sizeTol = (size + sizeSd)/1024/1024;
    NSString *str = [NSString stringWithFormat:@"您的缓存大小为:%.2fMB,是否清理缓存",sizeTol];
    UIAlertController *alterView = [UIAlertController alertControllerWithTitle:@"提示" message:str preferredStyle:UIAlertControllerStyleActionSheet];
    [self presentViewController:alterView animated:YES completion:^{
    }];
    UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
    }];
    UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
        [self clear];
        SDImageCache *sd = [SDImageCache sharedImageCache];
        [sd clearDisk];
    }];
    [alterView addAction:action1];
    [alterView addAction:action2];
}

- (void)clear
{
    NSString *path = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)lastObject];
    NSLog(@"%@",path);
    NSArray *childPath = [[NSFileManager defaultManager]subpathsAtPath:path];
    for (NSString *child in childPath) {
        
        if (![child isEqualToString:@"MyProject.sqlite"]) {
            NSString *string = [path stringByAppendingPathComponent:child];
            [[NSFileManager defaultManager]removeItemAtPath:string error:nil];
        }
    }
   
    NSString *path1 = [NSString stringWithFormat:@"%@/tmp",NSHomeDirectory()];
    NSArray *childPath1 = [[NSFileManager defaultManager]subpathsAtPath:path1];
    for (NSString *child1 in childPath1) {
        
        NSString *sting1 = [path1 stringByAppendingPathComponent:child1];
        [[NSFileManager defaultManager] removeItemAtPath:sting1 error:nil];
    }
    
    
    NSString *path2 = [NSString stringWithFormat:@"%@/Library/Cache",NSHomeDirectory()];
    NSArray *childPath2 = [[NSFileManager defaultManager]subpathsAtPath:path2];
    for (NSString *child2 in childPath2) {
        
        NSString *string2 = [path2   stringByAppendingString:child2];
        [[NSFileManager defaultManager] removeItemAtPath:string2 error:nil];
    }
}

- (CGFloat)sizeOfClear
{
    NSString *string = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)lastObject];
    NSFileManager *fileManger = [NSFileManager defaultManager];
    CGFloat CacheSise  = [[fileManger attributesOfItemAtPath:string error:nil] fileSize];
    
      NSString *path1 = [NSString stringWithFormat:@"%@/tmp",NSHomeDirectory()];
    CGFloat tmpsize = [[fileManger attributesOfItemAtPath:path1 error:nil] fileSize];
    NSString *path2 = [NSString stringWithFormat:@"%@/Library/Cache",NSHomeDirectory()];
    CGFloat cachesize = [[fileManger attributesOfItemAtPath:path2 error:nil] fileSize];
    
    return CacheSise + tmpsize + cachesize;
}


//美物:

- (IBAction)good:(UIButton *)sender
{
    MybutifulgoodsViewController *butifluGood = [[MybutifulgoodsViewController alloc]init];
    [self.navigationController pushViewController:butifluGood animated:YES];
}
@end
